$(function () {
    $("#code").click(function () {
        $("#code").attr("src","CheckCodeController?action=login"+new Date());
    })

    $("a:eq(0)").click(function () {
        $("#code").attr("src","CheckCodeController?action=login"+new Date());
    })

    $("#register").click(function () {
        window.location.href="http://localhost:8080/smart_movies/register.html";
    })


    //更加AJAX获取后端数据
    const LOGIN_URL="http://localhost:8080/smart_movies/LoginController";

    $("#login").click(function () {
        var name = $("input:eq(0)").val();
        var userPassword = $("input:eq(1)").val();
        var userCode = $("input:eq(2)").val();
        var parsem={
            username:name,
            password:userPassword,
            code:userCode
        }

        $.post(LOGIN_URL,parsem,function (result) {
            if (result.status===200){
                window.location.href="http://localhost:8080/smart_movies/index.html";
            }else if (result.status===404){
                alert(result.msg);
                window.location.href="http://localhost:8080/smart_movies/login.html";
            }else if (result.status===201){
                alert(result.msg);
                window.location.href="http://localhost:8080/smart_movies/login.html";
            }
        })

    })
})
